Exception type thrown upon any failure.
Called automatically upon a comparison for ordering using one of the operators <, <=, >, or >=. In case the comparison is erroneous (i.e. it would make a signed negative value appear greater than or equal to an unsigned positive value), throws a Throw.CheckFailure exception. Otherwise, the three-state result is returned (positive if lhs > rhs, negative if lhs < rhs, 0 otherwise).
Called automatically upon a comparison for equality. Throws upon an erroneous comparison (one that would make a signed negative value appear equal to an unsigned positive value).
Called automatically upon a bad cast (one that loses precision or attempts to convert a negative value to an unsigned type). The source type is Src and the destination type is Dst.
Called automatically upon a bounds error.
Called automatically upon an overflow during a unary or binary operation.
Called automatically upon a bounds error.
1 void test(T)() 2 { 3 Checked!(int, Throw) x; 4 x = 42; 5 auto x1 = cast(T) x; 6 assert(x1 == 42); 7 x = T.max + 1; 8 import std.exception; 9 assertThrown(cast(T) x); 10 x = x.max; 11 assertThrown(x += 42); 12 assertThrown(x += 42L); 13 x = x.min; 14 assertThrown(-x); 15 assertThrown(x -= 42); 16 assertThrown(x -= 42L); 17 x = -1; 18 assertNotThrown(x == -1); 19 assertThrown(x == uint(-1)); 20 assertNotThrown(x <= -1); 21 assertThrown(x <= uint(-1)); 22 } 23 test!short; 24 test!(const short); 25 test!(immutable short);
Force all integral errors to fail by throwing an exception of type Throw.CheckFailure. The message coming with the error is similar to the one printed by Warn.